import SkuFieldTypeEnum from '@/framework/components/sku/SkuFieldTypeEnum'
import DisplayModeEnum from '@/framework/components/sku/DisplayModeEnum'

export default class SkuField {
  constructor({
    name,
    title,
    value = '',
    displayMode = DisplayModeEnum.ALL,
    fieldType = SkuFieldTypeEnum.TEXT,
    required = true,
    ...extra
  }) {
    this.name = name
    this.addFlag = 1
    this.value = value
    this.title = title
    this.displayMode = displayMode
    this.required = required
    this.fieldType = fieldType
    Object.assign(this, extra)
  }

  clone() {
    return new SkuField({
      ...this
    })
  }

  get isDisplayEditMode() {
    return this.displayMode === DisplayModeEnum.EDIT || this.displayMode === DisplayModeEnum.ALL
  }

  get isDisplayAddMode() {
    return this.displayMode === DisplayModeEnum.ADD || this.displayMode === DisplayModeEnum.ALL
  }

  get isIntegerField() {
    return this.fieldType === SkuFieldTypeEnum.INTEGER
  }

  get isIntegerIncAndDecField() {
    return this.fieldType === SkuFieldTypeEnum.INTEGER_INC_DEC
  }

  get isFloatField() {
    return this.fieldType === SkuFieldTypeEnum.FLOAT
  }

  get isImageField() {
    return this.fieldType === SkuFieldTypeEnum.IMAGE
  }

  get isRadioField() {
    return this.fieldType === SkuFieldTypeEnum.RADIO
  }

  get isDefaultSkuField() {
    return this.fieldType === SkuFieldTypeEnum.DEFAULT_SKU
  }

  get isOnlineOfflineField() {
    return this.fieldType === SkuFieldTypeEnum.ONLINE_OFFLINE
  }

  get isTextField() {
    return this.fieldType === SkuFieldTypeEnum.TEXT
  }
}
